Skip to content

feat(provider): 0.10.13 — reuse scoped Gemma image features in bounded RAM, off by default (port of fork #13; ships with platform #609) - #1947

Draft
jonathan308 wants to merge 2 commits into
devfrom
feat/gemma-image-feature-cache
Draft

jonathan308 wants to merge 2 commits into
devfrom
feat/gemma-image-feature-cache

Conversation

@jonathan308

@jonathan308 jonathan308 commented Nov 9, 2026 •

Copy link
Copy Markdown
Collaborator

Draft for 0.10.13, opt-in and off by default; ships with darkbloom-platform#609 (the coordinator's
vision_cache_scope; owned by the S-PLAT sweep; a draft). Moved from 0.10.12 on 2026-11-09; not part of the five-port
review of #1941–#1945. Head bb81bd78f8; CI (dev) run 42700784572: success (21 jobs). Independent refactor pass
done (2026-11-09, no behavior change; see Refactor pass). Port of the private draft jonathan308/d-inference#13
(2026-10-29), which never landed. Red first: a new feature, so its red is a local mutant (lookups forced to miss:
20 tests, 42 issues); see Test plan. Not for merge until reviewed, with #609.

Summary

Repeated still images rerun Gemma's vision tower and projector. With DARKBLOOM_VISION_FEATURE_CACHE=1 (default
off), evaluated CPU feature bytes are reused within one coordinator-authenticated account scope. Decoding and
resizing still run, the current prompt and its spans are rebuilt, and the language model's prefill runs in full; only the
per-image encoder work is skipped. Missing scope, the flag off, an unsupported model or processor, and video take the
cold path. Local requests have no shared scope.

Bounds: one process ledger charges every byte: 64 MiB process, 32 MiB slot, 16 MiB scope, 8 MiB entry, a 60 s
absolute TTL. Pending copies and pinned retired entries stay charged; a full scope never evicts another account's
entries; an MLX fault invalidates the cache generation; shutdown cancels and drains preparation before refunds.

Wire: an optional inbound vision_cache_scope (with platform #609); the terminal profile gains optional
vision_feature_cache_hits and vision_encoder_images (counts only: no scope, digest or image). No cached-token credit;
output budgets, deadlines and billing are unchanged.

Before

flowchart LR
  A["image request"] --> B["decode and resize"]
  B --> C["vision tower and projector, every time"]
  C --> D["prompt with spans; full prefill"]
  classDef work fill:#fff3cd,stroke:#805d00,color:#382900
  class B,C work
Loading

After

flowchart LR
  A["trusted outer vision_cache_scope (coordinator)"] --> B["decode and resize the current image"]
  B --> C{"qualified feature hit in this scope?"}
  C -- yes --> D["restore a fresh MLX array from charged CPU bytes"]
  C -- no --> E["run the tower; keep a bounded CPU snapshot"]
  D --> F["current prompt with spans; full prefill"]
  E --> F
  classDef reuse fill:#d8f3dc,stroke:#23743b,color:#123d20
  class C,D reuse
Loading

Code: VisionFeatureCache, GemmaVisionFeatureCache, GemmaVisionProcessorIdentity, VisionFeaturePreparationOwner
(Inference/Vision/), EngineV2VisionPrefill, the bridge's lifecycle, GlobalKVCacheBudget's process ledger,
Messages/InferenceProfile/RequestProfileBuilder, the handler and the serve loop. Design:
docs/architecture/image-feature-cache.md (new).

Adapted to dev

  • The serve loop's arrival match (ProviderLoop+Serve, added on dev after the original's base) and the cluster
    member's request match (ProviderLoop+ClusterMember) take the new associated value.
  • Docs: every conflict was a freshness stamp or two appended sections; both sides kept.

Linked issue

None. Coordinator half: darkbloom-platform#609. Original: jonathan308/d-inference#13 (private).

Test plan

  • Local (Xcode 27.2, CPU sandbox, on dev 0f11fbe01a): VisionFeatureCacheTests (20), VisionFeatureCacheProfileTests
    (2), VisionFeaturePreparationOwnerTests (2), GemmaVisionProcessorIdentityTests (1), VisionCacheScopeProtocolTests
    (1), ProtocolTests (86), SSDOwnedEntryRetirementTests (22), MediaIngestTests (47): pass.
  • Red (mutant): with every lookup forced to miss, VisionFeatureCacheTests fails 20 tests with 42 issues
    (repeat reuse, LRU, scope quotas, expiry, shutdown drain).
  • CI (dev) run 42686035248 on 0bfd9a2a4d: success, provider and cluster (21 jobs). It also ran
    CoordinatorIntegrationTests and EngineV2BridgeTests, which need Metal (denied in the local sandbox).
  • make docs-check (212 files), docs-impact-check --base dev (50 files), changelog check, git diff --check.
  • Refactor pass (bb81bd78f8), local: the cache suites 26, ProtocolTests|SSDOwnedEntryRetirementTests|MediaIngestTests
    155, the isolated Swift 6 runner (warnings as errors) 26: pass (EngineV2VisionRoutingTests needs Metal, denied in
    the sandbox). CI (dev) run 42700784572 on bb81bd78f8: success, provider and cluster (21 jobs).
  • Not run for this port: the original's native qualification (live Gemma feature-bit parity, four 600-request load
    cells, lifecycle and billing audits) was on its October base; GemmaVisionFeatureCacheLiveTests is opt-in with real
    weights. The original measured repeated-image B2 first-content p50/p95 849.7/1118.1 ms OFF against 278.1/568.3 ms ON,
    and unique images slightly slower with the cache on (562.7 against 548.2 ms p50).

Open before merge (from the original)

  • Platform fix(provider,coordinator): make the memory cap bind in the two places it did not #609 must land with it (the scope comes only from the coordinator).
  • The original's last gate: two cache-ON image requests took 6.0 s and 11.0 s to their terminal despite ~365 ms first
    content (provider-path delays between the last delta and the terminal); the cause was not found.
  • Telemetry: the two profile counts must match the console's telemetry-types.ts mirror (platform side).

Components touched

  • provider-swift (Swift CLI)
  • docs

Protocol / interface changes

  • Yes: optional inbound vision_cache_scope, optional terminal-profile counts; older coordinators and providers
    ignore them. Matching side: darkbloom-platform#609.

Documentation impact

  • docs/architecture/image-feature-cache.md (new) and the architecture, developer, provider and reference pages it
    links; changelog.d/gemma-image-feature-cache.md.

Refactor pass

The original had an independent source/refactor review (cancellation and drain, quota isolation, invalid input). The
port's independent refactor pass
(2026-11-09, bb81bd78f8, no behavior change):

  • the cacheable-scope rule (not blank, ≤ 1 KiB), written three times, is VisionFeatureCache.isEligible(scope:); the
    process-wide entry cap is the budget's maxEntries instead of a literal 128;
  • two invariant comments the change dropped from EngineV2VisionPrefill.prepare are back (native templating binds to
    the loaded wrapper; inline media leaves no plaintext file);
  • docs vs code: DARKBLOOM_VISION_FEATURE_CACHE is not forwarded to the LaunchAgent, so only a foreground provider
    reads it; configuration.md and cli-reference.md now say so.
  • Checked by hand: every 15-value inferenceRequest match binds the right positions (a wrong one would still compile:
    visionCacheScope and serviceReservationID are both String?); fix(provider,coordinator): make the memory cap bind in the two places it did not #609's field names match.
  • Left for a follow-up: the scheduler now prepares through the bridge's cache only when no EngineV2VisionPlumbing is
    injected, so .production.prepare is no longer called and no routing test shows the cache, scope and profile reach
    the preparer; widening the seam touches ~33 test sites in other suites.

AI usage: ported by Claude Opus 5.5 (S-DINF sweep) at the owner's request. Not for merge until reviewed.

…-in, off by default)

Port of jonathan308/d-inference#13 (private fork, 2026-10-29) onto dev, for
0.10.12. It is the provider half of darkbloom-platform#609, which sends the
authenticated `vision_cache_scope`; it ships with that PR.

Repeated still images rerun Gemma's vision tower and projector. With
DARKBLOOM_VISION_FEATURE_CACHE=1 (default off), evaluated CPU feature bytes
are reused within one account scope: the image is still decoded and
resized, the prompt and its spans are rebuilt, and the language model's
prefill runs in full. Missing scope, the flag off, an unsupported model or
processor, and video take the cold path; local requests have no shared
scope.

- VisionFeatureCache: keys bind the scope, the loaded model, processor and
  config identity, the device, the raw payload digest, the normalized image
  bytes, dtype, shape and frame geometry. One process ledger charges every
  byte (64 MiB process, 32 MiB slot, 16 MiB scope, 8 MiB entry, 60 s TTL);
  pending copies and pinned retired entries stay charged; a full scope never
  evicts another scope; MLX faults invalidate the generation.
- Protocol: an optional inbound `vision_cache_scope`; the terminal profile
  gains optional `vision_feature_cache_hits` and `vision_encoder_images`
  (counts only; no scope, digest or image). No cached-token credit.
- Wiring: EngineV2VisionPrefill, the bridge's lifecycle and shutdown drain,
  GlobalKVCacheBudget's process ledger, the handler and serve loop.
- Adapted to dev: the serve loop's arrival match (ProviderLoop+Serve) and the
  cluster member's request match (ProviderLoop+ClusterMember) take the new
  associated value. Docs merged beside dev's new sections.

Tests: VisionFeatureCacheTests (20), VisionFeatureCacheProfileTests,
VisionFeaturePreparationOwnerTests, GemmaVisionProcessorIdentityTests,
VisionCacheScopeProtocolTests pass locally (CPU); ProtocolTests (86),
SSDOwnedEntryRetirementTests (22), MediaIngestTests (47) pass. With lookups
forced to miss (a local mutant, not committed), VisionFeatureCacheTests
fails 20 tests with 42 issues. The live Gemma test is opt-in (real weights).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
d-inference-landing Ready Ready Preview Nov 9, 2026 9:16pm UTC
darkbloom-status Ready Ready Preview Nov 9, 2026 9:16pm UTC
eigen-homepages-darkbloom Ready Ready Preview Nov 9, 2026 9:16pm UTC

Request Review

… docs say foreground only

Independent refactor pass of this port (#1947). No behavior change.

- The scope rule (not blank, at most 1 KiB) was written three times: in
  `EngineV2VisionPrefill.prepare`, `gemmaImageFeatures` and
  `VisionFeatureCache.Key`. It is now `VisionFeatureCache.isEligible(scope:)`.
- The process-wide entry cap (128) is the budget's `maxEntries`, beside its
  byte cap, instead of a literal in `reserve`.
- Restores two invariant comments the change dropped from
  `EngineV2VisionPrefill.prepare`: native tool templating binds to the
  loaded wrapper, not a caller's model label; inline media stays in the
  UserInput's memory-backed asset, so no plaintext file is left to clean up.
- `DARKBLOOM_VISION_FEATURE_CACHE` is not in the LaunchAgent passthrough, so
  only a foreground provider reads it; configuration.md and
  cli-reference.md said only "the provider process environment".

Local (Xcode 27.2, CPU sandbox): VisionFeatureCacheTests and the cache's
profile, owner, processor-identity and scope-protocol suites 26;
ProtocolTests, SSDOwnedEntryRetirementTests, MediaIngestTests 155: pass. The
isolated Swift 6 runner (warnings as errors) 26: pass. EngineV2VisionRoutingTests
needs Metal (denied here); CI runs it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch was successfully deployed

3 active deployments
Preview – d-inference-landing — bb81bd78 Deployed Nov 9, 2026 by vercel[bot]
Preview – eigen-homepages-darkbloom — bb81bd78 Deployed Nov 9, 2026 by vercel[bot]
Preview – darkbloom-status — bb81bd78 Deployed Nov 9, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant